<?php
/**
 * Created by Command.
 * User: Vito
 */

declare (strict_types = 1);

namespace app\model;

class PayRecordCopy extends BaseModel
{
    protected $name = 'PayRecord';
    /**
     * @Description: 关联房间表
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-10-29 11:31:50
     * @version: 1.0.0
     * @return [type]
     */
    public function room()
    {
        return $this->belongsTo('room', 'room_id')->with('building')->bind(
            [
                'room_name' => 'name'
            ]
        );
    }
    /**
     * @Description: 远程一对一关联楼房表
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-10-29 11:35:36
     * @version: 1.0.0
     * @return [type]
     */
    public function building()
    {
        return $this->hasOneThrough('building', 'room', 'id', 'id', 'room_id', 'building_number');
    }
    /**
     * @Description: 关联用过户表
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-10-29 14:55:00
     * @version: 1.0.0
     * @return [type]
     */
    public function User()
    {

        return $this->belongsTo('user', 'user_id')->bind([
            'room_name' => 'real_name'
        ]);
    }


    /**
     * @Description: 关联管理员表
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-12-14 1130:00
     * @version: 1.0.0
     * @return [type]
     */
    
     public function admin(){
        return $this->belongsTo('admin', 'payee');
     }

    /**
     * @Description: 获取要导出的缴费记录
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-12-03 10:27:49
     * @version: 1.0.0
     * @return [type]
     */    
    public static function getExportList($where){

        // $where['pid'] = ['<>',0];

        $res = self::where($where)->order('id','desc')->with(['room','User'])
        ->alias('PayRecord')
        ->field(['Room.id' => 'room_id', 'PayRecord.*'])
        ->join('wuye_room Room', 'Room.id = PayRecord.room_id', 'right')
        ->select();

        return $res;
    }   
}
